package com.wn.common.dialog

import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.wn.common.databinding.DialogSexChooseBinding
import com.wn.framework.base.BaseDialog
import com.wn.framework.base.BaseDialogFragment
import com.wn.framework.ext.onClick

/**
 * @Author: wn
 * @Date: 2025/8/1 17:21
 * @Description: 性别选择弹框 -- setOnSexChooseCall 方法中 传入 lambda 中 获取 选择的 性别
 */
class ChooseSexDialog {
  class Builder(activity: FragmentActivity) : BaseDialogFragment.Builder<Builder>(activity) {
    private var mOnSexChooseCall: ((String) -> Unit)? = null

    /**
     * 此处为实例 的 XML 布局
     */
    private val mBinding: DialogSexChooseBinding =
      DialogSexChooseBinding.inflate(LayoutInflater.from(activity))

    init {
      initView()
    }

    private fun initView() {
      // 绑定 实例 布局
      setContentView(mBinding.root)
      setWidth(ViewGroup.LayoutParams.MATCH_PARENT)
      setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
      setAnimStyle(BaseDialog.AnimStyle.BOTTOM)
      gravity = Gravity.BOTTOM

      // 点击 调用 传入的  lambda  获取 性别 男
      mBinding.clSexBoy.onClick {
        mOnSexChooseCall?.invoke(getString(com.wn.framework.R.string.user_sex_boy))
        dismiss()
      }
      // 点击 调用 传入的  lambda  获取 性别 女
      mBinding.clSexGirl.onClick {
        mOnSexChooseCall?.invoke(getString(com.wn.framework.R.string.user_sex_girl))
        dismiss()
      }
      mBinding.tvCancel.onClick {
        dismiss()
      }
    }

    /**
     * 获取 选择 的 性别
     * @param onSexChooseCall Function1<String, Unit>
     * @return Builder
     */
    fun setOnSexChooseCall(onSexChooseCall: ((String) -> Unit)): Builder {
      mOnSexChooseCall = onSexChooseCall
      return this
    }
  }
}